home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Day Cry
/
Day Cry CD.bin
/
oh_towns
/
tetujin
/
src.lzh
/
GRATIF.C
< prev
next >
Wrap
Text File
|
1994-09-04
|
6KB
|
283 lines
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <winb.h>
#include <te.h>
#include <fntb.h>
#include <gui.h>
#include <file_dlg.h>
#include <tifflib.h>
#include <egb.h>
#include <mos.h>
#include <snd.h>
#include "tetujin.h"
static FILE *fptif ;
static int xtif, ytif ;
static int colorMode ;
static char *imageBuf ;
static int counter ;
/* tiff check head (stack:4096Byteê╚Åπ) */
tiffCheckHead( char *name, int *c, int *x, int *y,
int *comp, int *fill, long *strip, long *clut )
{
FILE *fp ;
char work[4096] ;
if( ( fp = fopen( name, "rb" ) ) == NULL )return READ_FAIL ;
/* âtâ@âCâïâIü[âvâô */
fread( work, 1, 4096, fp ); /* ì┼Åëé╠âfü[â^âìü[âh */
/* âwâbâ_é╠ë≡É═ */
if( TIFF_getHead( work, 4096 ) < 0 ){
fclose( fp );
return ILLEGAL_DATA ;
}
fclose( fp );
/* â^âOé╠ôαùeé╠â`âFâbâN */
*c = TIFF_checkMode( x, y, comp, fill, strip, clut );
return NOERR ;
}
/*
1600û£ÉFùp TIFF loader
32k, 1600û£ÉFé╠tifdataé≡1600û£ÉFâfü[â^é╔ò╧è╖é╡é╚é¬éτô╟é▌ì₧é▐í
worké═ DECOMP_WORK_SIZE + LOADBUFSIZE + EXPBUFSIZEâoâCâgòKùví
âtâ@âCâïû╝nameé╠tifé≡âoâbâtâ@bufferé╔ô╟é▌Åoé╖í
dx, dyé╔èGé╠æσé½é│é≡ò╘é╖í
*/
/* âëâCâuâëâèé⌐éτî─é╬éΩéΘüCâoâbâtâ@é╔æ╬é╖éΘæÇì∞é╠è╓Éö */
static tifLoadGet( bp, size )
char *bp ;
int size ;
{
if( fread( bp, size, 1, fptif ) < 1 )
return -1 ;
return NOERR ;
}
static tifLoadPut( buf, lofs, lines )
char *buf ;
int lofs, lines ;
{
int i ;
if( lofs*xtif + lines*xtif > xtif*ytif )
return -1 ;
if( colorMode == 24 )
{
for( i=0 ; i<lines*xtif*3 ; i++ )
{
BYTE( imageBuf + lofs*xtif*3 + i )
= BYTE( buf + i ) ;
}
}
else if( colorMode == 16 )
{
for( i=0 ; i<lines*xtif ; i++ )
{
int temp, r, g, b ;
temp = WORD( buf + i*2 ) ;
b = temp & 0x1f ;
r = ( temp >> 5 ) & 0x1f ;
g = ( temp >> 10 ) & 0x1f ;
b <<= 3 ; r <<= 3 ; g <<= 3 ;
BYTE( imageBuf + lofs*xtif*3 + i*3 ) = r ;
BYTE( imageBuf + lofs*xtif*3 + i*3 + 1 ) = g ;
BYTE( imageBuf + lofs*xtif*3 + i*3 + 2 ) = b ;
}
}
return NOERR ;
}
tifLoad16m( char *work, char *name, char *buffer, int *dx, int *dy )
{
char *lbp, *dbp, *cbuf ;
int lbsize, dbsize,bpp, d_line ;
int comp, fill ;
long strip, clut, dw ;
imageBuf = buffer ;
lbsize = LOADBUFSIZE ; /* é╗éΩé╝éΩé╠âoâbâtâ@é╠âTâCâY */
dbsize = EXPBUFSIZE ;
lbp = work; /* âìü[âhâoâbâtâ@ */
dbp = lbp + lbsize; /* ôWèJâoâbâtâ@ */
cbuf = dbp + dbsize; /* ê│ÅkôWèJùpâÅü[âN */
/* DECOMP_WORK_SIZEé¬tifflib.hé╔ÆΦï`é│éΩé─éΘé¬
lbsize+dbsize+DECOMP_WORK_SIZEé¬worké╠æσé½é│é≡
é▒éªé╚éóéµéñé╔Æìê╙é╖éΘé▒é╞ */
if( ( fptif = fopen( name, "rb" ) ) == NULL )return READ_FAIL ;
/* âtâ@âCâïâIü[âvâô */
fread( lbp, 1, lbsize, fptif ); /* ì┼Åëé╠âfü[â^âìü[âh */
/* lbsizeÆ÷é╠âfü[â^é¬û│é¡é─éαok! */
/* âwâbâ_é╠ë≡É═ */
if( TIFF_getHead( lbp, lbsize ) < 0 ){
fclose( fptif );
return ILLEGAL_DATA ;
}
/* â^âOé╠ôαùeé╠â`âFâbâN */
bpp = TIFF_checkMode( &xtif,&ytif,&comp,&fill,&strip,&clut );
if( (bpp != 16) && (bpp != 24) ){
fclose( fptif );
return ILLEGAL_DATA ;
}
colorMode = bpp ;
*dx = xtif ;
*dy = ytif ;
/* âoâbâtâ@æÇì∞è╓Éöé╠ôoÿ^ */
TIFF_setLoadFunc( tifLoadPut, tifLoadGet ) ;
dw = xtif ;
/* 16ÉFâéü[âhé╠ÅΩìç,ëíò√îⁿé≡8âhâbâgÆPê╩é┼ê╡éñé╜é▀üCêΩìsé╠âfü[â^
âTâCâYé≡îvÄZé╖éΘì█é╔üC8âhâbâgÆPê╩é╔Æ▓É«é╡é─é¿é¡òKùvé¬éáéΘ */
// if( bpp == 4)
// if( dw & 7 )
// dw += 8 - (dw & 7) ;
/* ôWèJùpâoâbâtâ@é╔ë╜ìsò¬é╠âfü[â^é¬ôⁿéΘé⌐é╠îvÄZ */
d_line = dbsize / ((dw * bpp + 7)/ 8) ;
/* TIFFâfü[â^ô╟é▌ì₧é▌ */
TIFF_loadImage( bpp,xtif,ytif,strip, fill, comp, dbp, dw, d_line, cbuf );
fclose( fptif );
return NOERR ;
}
/* 1600û£ÉFé⌐éτ32kÉFé╔ò╧è╖é╖éΘè╓Éö */
cov16mTo32k( char *sour, char *dest, int n )
{
int i, r, g, b ;
for( i=0 ; i<n ; i++ )
{
r = BYTE( sour + i*3 ) ;
g = BYTE( sour + i*3 + 1 ) ;
b = BYTE( sour + i*3 + 2 ) ;
r >>= 3 ; g >>= 3 ; b >>= 3 ;
WORD( dest + i*2 ) = b + (r << 5) + (g << 10) ;
}
return NOERR ;
}
/*
1600û£ÉFùp TIFF saver
1600û£ÉFé╠tifdataé≡bufferé⌐éτsaveí
worké═ COMP_WORK_SIZE + SAVEBUFSIZE + GETBUFSIZEâoâCâgòKùví
âtâ@âCâïû╝é═nameí
x, yé═èGé╠æσé½é│í
*/
/* âëâCâuâëâèé⌐éτî─é╬éΩéΘüCâoâbâtâ@é╔æ╬é╖éΘæÇì∞é╠è╓Éö */
static tifSavePut( bp, size )
char *bp ;
int size ;
{
if( fwrite( bp, size, 1, fptif ) < 1 )
return -1 ;
counter += size ;
return NOERR ;
}
static tifSaveGet( buf, lofs, lines )
char *buf ;
int lofs, lines ;
{
int i ;
if( lofs*xtif + lines*xtif > xtif*ytif )
return -1 ;
if( colorMode == 24 )
{
for( i=0 ; i<lines*xtif*3 ; i++ )
{
BYTE( buf + i )
= BYTE( imageBuf + lofs*xtif*3 + i ) ;
}
}
else if( colorMode == 16 )
{
for( i=0 ; i<lines*xtif*2 ; i++ )
{
BYTE( buf + i )
= BYTE( imageBuf + lofs*xtif*2 + i ) ;
}
}
return NOERR ;
}
tifSave32kAnd16m
(
char *work, char *name, char *buffer, int bpp, int comp, int x, int y
)
{
char *sbp, *ibp, *cbuf ;
int sbsize, ibsize, i_line, compsize, dw ;
if( (bpp != 16) && (bpp != 24) )
return ILLEGAL_DATA ;
colorMode = bpp ;
imageBuf = buffer ;
if( comp )comp = 5 ;
else comp = 1 ;
xtif = x ;
ytif = y ;
counter = 0 ;
sbsize = SAVEBUFSIZE ; /* é╗éΩé╝éΩé╠âoâbâtâ@é╠âTâCâY */
ibsize = GETBUFSIZE ;
sbp = work; /* âìü[âhâoâbâtâ@ */
ibp = sbp + sbsize; /* ôWèJâoâbâtâ@ */
cbuf = ibp + ibsize; /* ê│ÅkôWèJùpâÅü[âN */
/* COMP_WORK_SIZEé¬tifflib.hé╔ÆΦï`é│éΩé─éΘé¬
sbsize+ibsize+DECOMP_WORK_SIZEé¬worké╠æσé½é│é≡
é▒éªé╚éóéµéñé╔Æìê╙é╖éΘé▒é╞ */
/* âtâ@âCâïâIü[âvâô */
if( ( fptif = fopen( name, "wb" ) ) == NULL )
return WRITE_FAIL ;
fseek( fptif, 512, SEEK_SET ); /* headerò¬èJé»éΘ */
/* âoâbâtâ@æÇì∞è╓Éöé╠ôoÿ^ */
TIFF_setSaveFunc( tifSavePut, tifSaveGet ) ;
dw = xtif ;
/* ôWèJùpâoâbâtâ@é╔ë╜ìsò¬é╠âfü[â^é¬ôⁿéΘé⌐é╠îvÄZ */
i_line = ibsize / ((dw * bpp + 7)/ 8) ;
/* TIFFâfü[â^save */
if
(
TIFF_saveImage( bpp,xtif,ytif,comp, sbp, sbsize, ibp, dw, i_line, cbuf )
<= 0
)
{
fclose( fptif ) ;
remove( name ) ; /* del */
return WRITE_FAIL ;
}
/* TIFF head */
if( comp == 1 )compsize = 0 ;
else compsize = counter ;
TIFF_setHead( ibp, bpp, xtif, ytif, compsize, ibp ) ;
fseek( fptif, 0, SEEK_SET );
if( fwrite( ibp, 512, 1, fptif ) < 1 )
{
fclose( fptif ) ;
remove( name ) ; /* del */
return WRITE_FAIL ;
}
fclose( fptif );
return NOERR ;
}